package com.jcl.recruit.log.logic;

import com.jcl.core.utils.StringUtils;
import com.jcl.recruit.core.constants.ResumeLogType;
import com.jcl.recruit.resume.logic.ResumePersInfoLogic;
import com.jcl.recruit.resume.model.ResumePersInfo;
import com.jcl.recruit.user.logic.UserLogic;
import com.jcl.recruit.user.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @ClassName ApplyResumeLog
 * @Description TODO
 * @Author yyliu
 * @Date 2018/9/20 10:10
 * @Version 1.0
 **/
@Component
public class ApplyResumeLog {

    @Autowired
    protected UserLogic userLogic;

    @Autowired
    private ResumePersInfoLogic resumePersInfoLogic;

    @Autowired
    private ResumeLogLogic resumeLogLogic;

    public int addResumeLog(String corpCode,
                            Integer userId,
                            Integer resumeId,
                            Integer category) {

        String content = getTemplateContent(corpCode, userId, resumeId, category);
        String resumeType = ResumeLogType.getResumeType(category);

        resumeLogLogic.addResumeLog(corpCode, userId, resumeId,
                content, category, resumeType);
        return 1;
    }

    public String getTemplateContent(String corpCode,
                                     Integer userId,
                                     Integer resumeId,
                                     Integer category) {

        String userName = StringUtils.EMPTY;
        String resumeName = "XX";
        User user = userLogic.findOneById(userId);
        if (null != user) {
            userName = user.getRealname();
            if (null == userName) {
                userName = user.getUsername();
            }
        }
        ResumePersInfo resume = resumePersInfoLogic.findOne(corpCode, resumeId);
        if (StringUtils.hasLength(resume.getName())) {
            resumeName = resume.getName();
        }
        String content = ResumeLogType.template(category, userName, resumeName, ResumeLogType.getTimestamp());
        return content;
    }


}
